package com.farm.code.server;

import com.farm.core.auth.domain.LoginUser;
import com.farm.core.time.TimeTool;
import com.farm.code.dao.FarmCodeProjectDaoInter;
import com.farm.code.domain.FarmCodeProject;
import com.farm.code.server.FarmCodeProjectManagerInter;
import com.farm.core.sql.query.DataQuery;

/**
 * 工程
 * 
 * @author MAC_wd
 */
public class FarmCodeProjectManagerImpl implements FarmCodeProjectManagerInter {
	private FarmCodeProjectDaoInter farmCodeProjectDao;
//	private static final Logger log = Logger
//			.getLogger(FarmCodeProjectManagerImpl.class);

	@Override
	public FarmCodeProject insertFarmCodeProjectEntity(FarmCodeProject entity,
			LoginUser user) {
		entity.setCuser(user.getId());
		entity.setCtime(TimeTool.getTimeDate14());
		entity.setCusername(user.getName());
		entity.setEuser(user.getId());
		entity.setEusername(user.getName());
		entity.setEtime(TimeTool.getTimeDate14());
		return farmCodeProjectDao.insertEntity(entity);
	}

	@Override
	public FarmCodeProject editFarmCodeProjectEntity(FarmCodeProject entity,
			LoginUser user) {
		FarmCodeProject entity2 = farmCodeProjectDao.getEntity(entity.getId());
		entity2.setEuser(user.getId());
		entity2.setEusername(user.getName());
		entity2.setEtime(TimeTool.getTimeDate14());
		entity2.setPstate(entity.getPstate());
		entity2.setPcontent(entity.getPcontent());
		entity2.setName(entity.getName());
		entity2.setTypeid(entity.getTypeid());
		entity2.setDirpath(entity.getDirpath());
		entity2.setType(entity.getType());
		entity2.setGraphid(entity.getGraphid());
		farmCodeProjectDao.editEntity(entity2);
		return entity2;
	}

	@Override
	public void deleteFarmCodeProjectEntity(String entity, LoginUser user) {
		// TODO 自动生成代码,修改后请去除本注释
		farmCodeProjectDao.deleteEntity(farmCodeProjectDao.getEntity(entity));
	}

	@Override
	public FarmCodeProject getFarmCodeProjectEntity(String id) {
		// TODO 自动生成代码,修改后请去除本注释
		if (id == null) {
			return null;
		}
		return farmCodeProjectDao.getEntity(id);
	}

	@Override
	public DataQuery createFarmCodeProjectSimpleQuery(DataQuery query) {
		// TODO 自动生成代码,修改后请去除本注释
		DataQuery dbQuery = DataQuery.init(query, "farm_code_project",
				"id,PSTATE,PCONTENT,NAME,DIRPATH,TYPE");
		return dbQuery;
	}

	// ----------------------------------------------------------------------------------
	public FarmCodeProjectDaoInter getfarmCodeProjectDao() {
		return farmCodeProjectDao;
	}

	public void setfarmCodeProjectDao(FarmCodeProjectDaoInter dao) {
		this.farmCodeProjectDao = dao;
	}

}
